package com.hpdz.hotel_back.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hpdz.hotel_back.entity.Employee;
import com.hpdz.hotel_back.entity.Task;
import com.hpdz.hotel_back.mapper.TaskMapper;
import com.hpdz.hotel_back.service.TaskService;
import com.hpdz.hotel_back.utils.MyPage;
import com.hpdz.hotel_back.vo.TaskVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements TaskService {

    @Resource
    private TaskMapper taskMapper;


    @Override
    public IPage<Task> listPage(Integer current, Integer size) {
        Page<Task> taskPage = new Page<>(current, size);
        return taskMapper.selectPage(taskPage,null);
    }

    @Override
    public MyPage<TaskVo> showAllTask(Integer current, Integer size) {
        MyPage<TaskVo> taskVoMyPage = new MyPage<>();
        Integer count = taskMapper.selectCount(null);
        List<TaskVo> list = taskMapper.selectAllPage((current-1)*size,size);
        taskVoMyPage.setTotal(count);
        taskVoMyPage.setList(list);
        return taskVoMyPage;
    }

    @Override
    public MyPage<TaskVo> showEmpTask(Integer current, Integer size, Employee emp) {
        MyPage<TaskVo> taskVoMyPage = new MyPage<>();
        Integer total = taskMapper.selectOnePage(0,Integer.MAX_VALUE,emp).size();
        String tmp = "%" + emp.getNickName() + "%";
        emp.setNickName(tmp);
        List<TaskVo> list = taskMapper.selectOnePage((current-1)*size,size,emp);
        taskVoMyPage.setTotal(total);
        taskVoMyPage.setList(list);
        return taskVoMyPage;
    }
}
